<?php


namespace app\model;


class DiscussModel extends BaseModel
{
    protected $table = 'forum_discuss';

    public function user(): \think\model\relation\HasMany
    {
        return $this->hasMany(UserModel::class, 'id', 'author_id')
            ->field(['id', 'name', 'img_id']);
    }

    /**
     * @throws \app\libs\exception\NotFoundException
     * @throws \app\libs\exception\ServerError
     */
    public function find_add_pv($id)
    {
        $discuss = self::with(['user', 'user.img'])
        ->field(['id', 'author_id', 'title', 'pv', 'create_time'])
        ->find($id);

        $this->isNoFound($discuss);

        $discuss->pv += 1;
        $discuss->save();
        return $discuss;
    }
}